from selenium.webdriver.common.by import By
from web_wechat_po.page_object.base_page import BasePage
from web_wechat_po.utils.log_utils import logger


class AddMemberPage(BasePage):

    # 添加成员元素
    __BTN_ADD_MEMBER = (By.CSS_SELECTOR,".ww_indexImg_AddMember")
    __INPUT_USERNAME = (By.XPATH,"//*[@id='username']")
    __INPUT_ACCTID = (By.XPATH, "//*[@id='memberAdd_acctid']")
    __INPUT_MOBILE = (By.XPATH, "//*[@id='memberAdd_phone']")
    __CLICK_SAVE = (By.CSS_SELECTOR, ".qui_btn.ww_btn.js_btn_save")

    # 添加部门元素
    __BTN_ADD_DEPARTMENT = (By.CSS_SELECTOR, ".member_colLeft_top_addBtn")
    __BTN_CHOICE_ADD_DEPARTMENT = (By.CSS_SELECTOR, ".js_create_party")
    __INPUT_DEPARTMENT_NAME = (By.NAME, "name")
    __BTN_CHOICE_DEPARTMENT = (By.CSS_SELECTOR, ".js_parent_party_name")
    __BTN_CHOICE__SUB_DEPARTMENT = (By.CSS_SELECTOR, ".form>div>div>div>ul>li>a")
    __CLICK_CONFIRM = (By.CSS_SELECTOR, ".ww_dialog_foot>.ww_btn_Blue")

    def add_member_info(self,username,acctid,mobile):
        # 2.点击添加成员按钮
        logger.info("点击添加成员按钮")
        self.do_find(self.__BTN_ADD_MEMBER).click()
        # 3.填写成员信息
        logger.info("填写成员信息")
        # 3.1.输入用户名
        self.do_find(self.__INPUT_USERNAME).send_keys(username)
        # 3.2.输入用户账号
        self.do_find(self.__INPUT_ACCTID).send_keys(acctid)
        # 3.3.输入手机号码
        self.do_find(self.__INPUT_MOBILE).send_keys(mobile)
        # 3.4.点击保存按钮
        logger.info("点击保存")
        self.do_find(self.__CLICK_SAVE).click()

        # ==》成员列表
        from web_wechat_po.page_object.contact_page import ContactPage
        return ContactPage(self.driver)

    def add_department(self, department):
        logger.info("点击添加部门按钮")
        # 1. 点击添加部门按钮
        self.do_find(self.__BTN_ADD_DEPARTMENT).click()
        # 2. 选择添加部门
        logger.info("选择添加部门")
        self.do_find(self.__BTN_CHOICE_ADD_DEPARTMENT).click()
        # 3. 填写部门信息
        logger.info("填写部门信息")
        # 3.1. 填写部门名称
        self.do_find(self.__INPUT_DEPARTMENT_NAME).send_keys(department)
        # 3.2. 点击所属部门
        self.do_find(self.__BTN_CHOICE_DEPARTMENT).click()
        # 3.3. 选择所属部门
        self.do_find(self.__BTN_CHOICE__SUB_DEPARTMENT).click()
        # 3.4. 点击确认按钮
        logger.info("点击确认")
        self.do_find(self.__CLICK_CONFIRM).click()

        from web_wechat_po.page_object.contact_page import ContactPage
        return ContactPage(self.driver)